<%@ page import="org.poliglot.syllab.HyphenatorEngine" %>
<%@ page import="org.poliglot.syllab.tex.TexHyphenator" %>
<%@ page import="org.poliglot.ipa.PhoneticTranslator" %>
<%@ page import="java.util.Properties" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%

    boolean success = false;
    String result = "";

    String lang = request.getParameter( "lang" );
    String input = request.getParameter( "input" );
    String hyphenate = request.getParameter( "hyphenate" );

    try
    {

        if ( input != null && input.length() > 0 )
        {
            HyphenatorEngine hyphenator = new TexHyphenator( Thread.currentThread().getContextClassLoader().getResourceAsStream( "hyph-es.tex" ) );

            if ( Boolean.valueOf( hyphenate ) )
            {
                input = hyphenator.hyphenate( input );
            }

            Properties props = new Properties();
            props.load( Thread.currentThread().getContextClassLoader().getResourceAsStream( "phonetics.properties" ) );

            Class<?> phoneticTranslatorClass = Class.forName( ( String ) props.get( lang ) );

            PhoneticTranslator translator = ( PhoneticTranslator ) phoneticTranslatorClass.newInstance();

            result = translator.parse( input );
            success = true;
        }
    }
    catch ( Exception e )
    {
        success = false;
        e.printStackTrace();

    }
    finally
    {
        out.print( "{" );

        out.print( "result: \"" + result + "\"," );
        out.print( "success: " + success );

        out.print( "}" );
    }
%>